// commonFunctions.js
import Decimal from "decimal.js";

export const sumValues = (list: any[]) => {
  let total = {
    billAmount: "",
    interestDeduction: "",
  };
  list.forEach((item: any, _) => {
    let billAmountDecimal = new Decimal(item.billAmount || 0);
    let BillAmount = new Decimal(total.billAmount || 0);
    let InterestDeduction = new Decimal(total.interestDeduction || 0);
    let openDecimal = new Decimal(item.open || 0);
    let points = new Decimal(item.points || 0);
    total.billAmount = billAmountDecimal
      .mul(10000)
      .mul(openDecimal)
      .plus(BillAmount)
      .toString();
    total.interestDeduction = points
      .mul(billAmountDecimal)
      .div(100)
      .mul(10000)
      .plus(InterestDeduction)
      .toString();
  });
  return total;
};

